﻿using Framework.Core.Consts;
using Framework.SqlSugarCore.Abstractions;
using Framework.SqlSugarCore.Repositories;
using my.abp.Domain.Repositories.Menu;
using my.abp.Domain.Repositories.Role;
using my.abp.Domain.Shared.Entities;
using my.abp.Domain.Shared.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;

namespace my.abp.SqlSugarCore.Repositories.Menu
{
	public class SysMenuRepository : SqlSugarRepository<SysMenu>, ISysMenuRepository, ITransientDependency
	{
		public SysMenuRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider) : base(sugarDbContextProvider)
		{
		}

		/// <summary>
		/// 获取用户拥有按钮权限集合（缓存）
		/// </summary>
		/// <returns></returns>
		public async Task<List<string>> GetOwnBtnPermList(List<long> menuIdList)
		{
			return await _DbQueryable
				.Where(u => u.Type == MenuTypeEnum.Btn)
				.WhereIF(menuIdList.Count > 0, u => menuIdList.Contains(u.Id))
				.Select(u => u.Permission).ToListAsync();
		}

		/// <summary>
		/// 获取系统所有按钮权限集合（缓存）
		/// </summary>
		/// <returns></returns>
		public async Task<List<string>> GetAllBtnPermList()
		{
			return await _DbQueryable
					.Where(u => u.Type == MenuTypeEnum.Btn)
					.Select(u => u.Permission).ToListAsync();
		}
	}
}
